<template>
  <div class="box">
    <div class="all">
      <div class="top">数据大屏</div>
      <div class="cen">
        <!-- 左开始 -->
        <div class="le">
          <div class="a">
            <!-- 四个块 -->
            <div class="le_top">
              <div class="gai">问卷概况</div>
              <div class="nei">
                <div class="div ss dd">
                  未发布 <span class="blue">{{ total_0 }}</span>
                </div>
                <div class="div dd">
                  发布中 <span class="yellow">{{ total_1 }}</span>
                </div>
                <div class="div ss">
                  已结束 <span class="green">{{ total_2 }}</span>
                </div>
                <div class="div">
                  已删除 <span class="red">{{ total_3 }}</span>
                </div>
                <div class="ding">{{ total }}</div>
              </div>
            </div>
            <!-- 折线图 -->
            <div class="le_bot" ref="box1"></div>
          </div>
        </div>
        <!-- 左结束 -->
        <!-- 右开始 -->
        <div class="ri">
          <div class="b">
            <!-- 饼图 -->
            <div class="ri_top">
              <div class="bing"><span>答卷情况</span></div>
              <div class="xia">
                <!-- 饼 -->
                <div class="bing_nei" ref="pai"></div>
                <!-- 表 -->
                <div class="bing_bia">
                  <div class="bi">
                    <div class="ti" v-if="answeredY > answeredN">No.1已答</div>
                    <div class="ti" v-else>No.1未答</div>
                    <div class="zhu"></div>
                  </div>
                  <div class="bi">
                    <div class="ti" v-if="answeredY > answeredN">No.2未答</div>
                    <div class="ti" v-else>No.2已答</div>
                    <div class="zhu zhu2"></div>
                  </div>

                  <div style="color: white">答卷率:</div>
                  <div
                    style="
                      color: rgb(22, 232, 249);
                      font-size: 35px;
                      padding-left: 20px;
                    "
                  >
                    {{ answeredR * 100 }}%
                  </div>
                </div>
              </div>
            </div>
            <!-- 群组信息-->
            <div class="ri_bot">
              <div class="z">
                <div class="tuitle">群组信息</div>
                <div class="jiug">
                  <div class="gg e">
                    <div class="mou">创建群组数</div>
                    <div class="nmu">{{ groupNum }}</div>
                  </div>
                </div>
              </div>
            </div>
          </div>
        </div>
        <!-- 右结束 -->
      </div>
    </div>
  </div>
</template>

<script>
export default {
  created() {
    this.getQuestionnaireList();
    this.getGroupNum();
    // this.getSevenDate();
  },

  data() {
    return {
      questionnaireList: [], //未发布，正发布，已结束
      garbageList: [], //已删除

      total: 0, //问卷总数
      total_0: 0, //未发布
      total_1: 0, //正在发布
      total_2: 0, //已结束
      total_3: 0, //删除

      answeredY: 0, //回答数
      answeredN: 0, //未回答数
      answeredR: 0, //答卷率

      groupNum: 0, //群组数

      dataList: [], //记录7天的数据
    };
  },
  mounted() {
    this.getBar();
    this.getBing();
  },
  methods: {
    async getQuestionnaireList() {
      //两次向后端发送的请求应当放在一个函数内
      let name = window.sessionStorage.getItem("name");
      await this.$http({
        method: "post",
        url: "/queryQuestionnaireByNameN?name=" + name,
      }).then((response) => {
        this.questionnaireList = response.data.data;
      });

      await this.$http({
        method: "post",
        url: "/getQuestionnaireFromBinNY?name=" + name,
      }).then((response) => {
        this.garbageList = response.data.data;
        this.total_3 = response.data.data.length;
      });
      this.getData();
    },

    //获取左一数据
    getData() {
      for (var i in this.questionnaireList) {
        if (this.questionnaireList[i].status === "0") {
          this.total_0 += 1;
        } else if (this.questionnaireList[i].status === "1") {
          this.total_1 += 1;
        } else if (this.questionnaireList[i].status === "2") {
          this.total_2 += 1;
        } else {
          console.log("出错啦");
        }
        this.total = this.total_0 + this.total_1 + this.total_2 + this.total_3;
      }
    },

    //右下群组数
    async getGroupNum() {
      let name = window.sessionStorage.getItem("name");
      await this.$http({
        method: "post",
        url: "/userCreateGroupNumber",
        data: {
          userName: name,
        },
      }).then((response) => {
        this.groupNum = response.data.data;
      });
    },

    //返回最近七天的日期
    getDate() {
      let days = [];
      for (let i = 24 * 6; i >= 0; i -= 24) {
        //今天加上前6天
        let dateItem = new Date(new Date().getTime() - i * 60 * 60 * 1000); //使用当天时间戳减去以前的时间毫秒（小时*分*秒*毫秒）
        let y = dateItem.getFullYear(); //获取年份
        let m = dateItem.getMonth() + 1; //获取月份js月份从0开始，需要+1
        let d = dateItem.getDate(); //获取日期
        let h = dateItem.getHours(); //时
        let mi = dateItem.getMinutes(); //分
        let s = dateItem.getSeconds(); //秒
        m = this.addDate0(m); //给为单数的月份补零
        d = this.addDate0(d); //给为单数的日期补零
        h = this.addDate0(h);
        mi = this.addDate0(mi);
        s = this.addDate0(s);
        let valueItem = y + "-" + m + "-" + d + " " + h + ":" + mi + ":" + s; //组合
        days.push(valueItem); //添加至数组
      }
      return days;
    },

    //给日期加0
    addDate0(time) {
      if (time.toString().length == 1) {
        time = "0" + time.toString();
      }
      return time;
    },

    // 折线图
    async getBar() {
      let days = this.getDate();
      let name = window.sessionStorage.getItem("name");
      for (var i in days) {
        await this.$http({
          method: "post",
          url: "/releaseTimeInToday",
          data: {
            name: name,
            releaseTime: days[i],
          },
        }).then((response) => {
          // console.log(response.data.data);
          this.dataList[i]=response.data.data;
        });
      }

      let ec = this.$echarts.init(this.$refs.box1);
      var option = {
        // 图表的名字（在最左边的y轴上方显示）
        title: {
          text: "近7天内发布问卷数变化趋势",
          //   title样式
          textStyle: {
            color: "rgb(13,220,225)",
          },
        },
        // 设置x轴上数据的类别
        xAxis: {
          type: "category",
          data: ["第1天", "第2天", "第3天", "第4天", "第5天", "第6天", "第7天"],
          boundaryGap: false, //x轴起点 紧贴边缘
          axisLabel: {
            //x轴文字show: true,
            textStyle: {
              color: "#fff",
              //更改坐标轴文字颜色fontSize: 12//更改坐标轴文字大小
            },
          },
        },

        // 设置y轴
        yAxis: [
          {
            scale: true, //起点不从0开始  (适用于 数据十分相近的时候)

            type: "value",
            axisLabel: {
              //x轴文字show: true,
              textStyle: {
                color: "#fff",
                //更改坐标轴文字颜色fontSize: 12//更改坐标轴文字大小
              },
            },
          },
        ],
        series: [
          {
            type: "line",
            // data: [0, 15, 48, 36, 25, 26, 100],
            data:this.dataList,
            areaStyle: { color: "rgb(13,220,225)" },
            itemStyle: {
              color: "rgb(13,220,225)",
            },
          },
        ],

        // barWidth: "10%",
      };
      ec.setOption(option);
    },

    // 右上饼图
    async getBing() {
      let name = window.sessionStorage.getItem("name");
      await this.$http({
        method: "post",
        url: "/userResponseRate?name=" + name,
      }).then((response) => {
        this.answeredY = response.data.data.Answered;
        this.answeredN = response.data.data.NotAnswered;
        this.answeredR = (response.data.data.rate).toFixed(2);//只保留两位数字
      });
      let pai = this.$echarts.init(this.$refs.pai);
      var option = {
        tooltip: {
          trigger: "item",
        },
        legend: {
          bottom: "1%",
          left: "center",
          textStyle: {
            color: "white",
          },
        },
        series: [
          {
            name: "占比",
            type: "pie",
            radius: ["40%", "80%"],
            avoidLabelOverlap: false,
            itemStyle: {
              borderRadius: 10,
              borderColor: "#fff",
              borderWidth: 2,
            },
            label: {
              show: false,
              position: "center",
            },
            emphasis: {
              label: {
                show: true,
                fontSize: "20",
                fontWeight: "bold",
              },
            },
            labelLine: {
              show: false,
            },
            data: [
              { value: this.answeredN, name: "未答" },
              { value: this.answeredY, name: "已答" },
            ],
          },
        ],
      };
      pai.setOption(option);
    },
  },
};
</script>

<style lang="less" scoped>
* {
  margin: 0;
  padding: 0;
}
.box {
  width: 100%;
  // height: 740px;
  height: 680px;
  margin: 0;
  padding: 0;
  .all {
    width: 100%;
    height: 100%;
    /* border: 1px solid black; */
    background: url("@/assets/images/analyseScreen/bj.png") no-repeat;
    background-size: 100%;
    position: relative;
    .top {
      // width: 300px;
      height: 60px;
      line-height: 60px;
      // border: 1px solid green;
      color: rgb(253, 251, 251);
      text-align: center;
      font-size: 28px;
      position: absolute;
      top: 0;
      left: 50%;
      transform: translate(-50%);
    }
    .cen {
      width: 100%;
      height: 570px;
      display: flex;
      justify-content: space-between;
      // padding: 10px;
      padding: 135px;
      box-sizing: border-box;
      position: absolute;
      top: -127px;

      // 左边
      .le {
        // width: 350px;
        width: 390px;
        padding-top: 10px;

        height: 600px;
        //   background-color: #fff;
        background: url("@/assets/images/analyseScreen/左.png") no-repeat;
        // background-size: 350px 600px;
        background-size: 390px 600px;
        box-sizing: border-box;
        perspective: 1200px;

        //   background-color: yellow;
        .a {
          padding: 15px;
          padding-top: 30px;
          box-sizing: border-box;
          width: 100%;
          height: 100%;
          transform-style: preserve-3d;
          transform: rotateY(35deg);

          .le_top {
            width: 100%;
            height: 49%;
            //   background-color: rgb(70, 208, 16);

            //   margin-bottom: 10px;
            .gai {
              width: 100%;
              background: url("@/assets/images/analyseScreen/标题.png")
                no-repeat;
              background-size: 200px 30px;
              height: 30px;
              line-height: 30px;
              z-index: 2;
              margin-bottom: 10px;
              color: white;
              padding-left: 10px;
              box-sizing: border-box;
            }
            .nei {
              width: 520px;
              position: relative;
              padding: 0 20px;
              width: 100%;
              height: 210px;
              background: url("@/assets/images/analyseScreen/左内容.png")
                no-repeat;
              // background-size: 320px 210px;
              background-size: 370px 180px;
              display: flex;
              flex-wrap: wrap;
              // padding-top: 20px;
              // box-sizing: border-box;
              // justify-content:space-between
              .div {
                width: 90px;
                height: 40px;
                // background-color: rgb(255, 85, 0);
                color: white;
                text-align: center;
                span {
                  display: block;
                  text-align: center;
                  margin-top: 5px;
                  font-size: 25px;
                  font-weight: 700;
                }
              }
              .ss {
                margin-right: 140px;
              }
              .blue {
                color: rgb(13, 220, 225);
              }
              .yellow {
                color: rgb(224, 174, 63);
              }
              .green {
                color: rgb(46, 221, 176);
              }
              .red {
                color: rgb(207, 108, 131);
              }
              .ding {
                position: absolute;
                width: 50px;
                height: 50px;
                // background-color: #fff;
                left: 50%;
                top: 50%;
                transform: translate(-50%, -60%);
                // font-size: large;
                font-size: 25px;
                font-weight: 700;
                color: rgb(13, 220, 225);
              }
            }
          }
          .le_bot {
            width: 380px;
            height: 49%;
            // background-color: rgb(228, 84, 36);
          }
        }
      }
      .cent {
        width: 54%;
        height: 100%;
        // border: 1px solid rgb(214, 25, 8);
      }
      // 右边
      .ri {
        width: 390px;
        padding-top: 10px;
        height: 650px;
        // background-color: red;
        box-sizing: border-box;
        perspective: 1200px;

        .b {
          width: 380px;
          height: 620px;
          perspective: 1200px;

          // background-color: #fff;

          &::after {
            content: "";
            position: absolute;
            right: 0;
            top: 0;
            width: 380px;
            height: 600px;
            background: url("@/assets/images/analyseScreen/右1.png") no-repeat;
            background-size: 380px 280px;
            transform-style: preserve-3d;
            transform: rotateY(15deg);
          }
          .ri_top {
            z-index: 2;
            width: 380px;
            height: 280px;
            margin-bottom: 0px;
            position: relative;
            perspective: 1200px;
            transform-origin: right;
            transform: rotateY(-20deg);
            padding-top: 20px;

            .bing {
              margin-left: -20px;
              padding-left: 10px;
              // margin-top: 50px;
              width: 380px;
              height: 30px;
              line-height: 30px;
              background: url("@/assets/images/analyseScreen/标题.png")
                no-repeat;
              background-size: 250px 30px;
              color: white;
              font-weight: 700;
              transform-style: preserve-3d;
              transform-origin: right;
            }
            .xia {
              display: flex;
              margin-left: -20px;

              .bing_nei {
                margin-top: -30px;
                width: 190px;
                height: 250px;
                // background-color: #fff;
                padding: 15px;
                box-sizing: border-box;
                // padding-bottom: 50px;
              }
              .bing_bia {
                border: 1px solid rgb(208, 205, 205);
                margin-top: 20px;
                width: 140px;
                height: 180px;
                // background-color: #fff;
                padding: 15px 15px;
                box-sizing: border-box;
                .bi {
                  width: 120px;
                  height: 30px;
                  // background-color: rgb(161, 25, 25);
                  margin-bottom: 10px;
                  .ti {
                    color: #fff;
                    font-weight: 700;
                    font-size: 12px;
                  }
                  .zhu {
                    width: 100px;
                    height: 15px;
                    background-color: rgb(22, 232, 249);
                    // border: 0 1px 0 0 solid rgb(22, 232, 249);
                    border-radius: 0 10px 10px 0;
                  }
                  .zhu2 {
                    width: 80px;
                  }
                  .zhu3 {
                    width: 60px;
                  }
                  .zhu4 {
                    width: 50px;
                  }
                }
              }
            }
          }
          .ri_bot {
            .z {
              transform-style: preserve-3d;
              transform-origin: left;
              transform: rotateY(-30deg);

              .tuitle {
                transform: rotateY(25deg);
                transform: rotateX(5deg);
                transform: rotateZ(3deg);
              }
            }
            perspective: 1000px;

            width: 380px;
            // height: 300px;
            height: 280px;
            padding: 20px;
            padding-top: 20px;
            background-color: rgb(228, 84, 36);
            background: url("@/assets/images/analyseScreen/右2.png") no-repeat;
            background-size: 360px 300px;
            // overflow: hidden;
            box-sizing: border-box;

            .tuitle {
              width: 320px;
              height: 45px;
              line-height: 35px;
              background: url("@/assets/images/analyseScreen/右-下标题.png")
                no-repeat;
              background-size: 280px 45px;
              padding: 5px;
              box-sizing: border-box;
              margin-bottom: 10px;
              margin-top: 15px;
              color: #fff;
              transform: rotateZ(2deg);

              // transform-origin:right;
              // transform: rotateY(-15deg);
            }
            .jiug {
              // width: 330px;
              width: 1000px;
              display: flex;
              flex-wrap: wrap;
              justify-content: space-between;
              transform-origin: left;

              transform: rotateZ(4deg);

              .gg {
                width: 30%;
                // height: 60px;
                height: 130px;
                padding: 5px;
                box-sizing: border-box;
                background-color: rgb(11, 50, 105);
                text-align: center;
                .mou {
                  color: white;
                  // font-size: 13px;
                  font-size: 30px;
                }
                .nmu {
                  // font-size: 28px;
                  font-size: 40px;
                  color: rgb(22, 232, 249);
                }
              }
              .e {
                margin-bottom: 15px;
              }
            }
          }
        }
      }
    }
    .botlis {
      width: 800px;
      height: 160px;
      // background-color: rgb(239, 8, 43);
      margin: auto;
      padding: 0 30px;
      // padding-right: 30px;
      position: absolute;
      bottom: 0;
      left: 50%;
      transform: translate(-50%);
      // padding-top: 0;
      box-sizing: border-box;
      perspective: 1200px;
      background: url("@/assets/images/analyseScreen/下.png") no-repeat;
      background-size: 750px 160px;
      .c {
        width: 88%;
        height: 100%;
        margin: 10px;
        transform-style: preserve-3d;
        position: absolute;
        top: -20px;
        // transform-origin:left;
        transform: rotateX(45deg);
        // transform: translateY(20px);
        // 表格上的标题
        .ttt {
          padding-bottom: 10px;
          // padding-left: 15px;
          color: #fff;
          font-size: 16px;
        }
        .tab {
          width: 100%;
          height: 90%;
          // background-color: #fff;

          .tr {
            text-align: center;
            margin-top: 5px;
            line-height: 30px;
            height: 30px;
            color: #fff;
            display: flex;
            justify-content: space-evenly;
            align-items: center;
            span {
              width: 200px;
              height: 20px;
              line-height: 20px;
              font-size: 16px;
            }

            .one {
              border-radius: 8px;
              background-color: #f9ac41;
              margin-left: 15px;
            }
          }
          .deep {
            background-color: #0d2f6c;
          }
          .light {
            background-color: #113981;
          }
        }
      }
    }
  }
}
</style>